package com.nineclock.common.exception;

import com.nineclock.common.entity.Result;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;



/**
 * 全局异常处理器
 */
@ControllerAdvice(annotations = {RestController.class, Controller.class})
@ResponseBody
public class BaseExceptionHandle {

    @ExceptionHandler(value = NcException.class) //处理异常的类型
    public Result exceptNcExcption(NcException e) {
        e.printStackTrace();
        return Result.errorCodeMessage(e.getCode(),e.getMessage());
    }

    @ExceptionHandler(value = Exception.class)
    public Result except(Exception e) {
        e.printStackTrace();
        return Result.errorMessage("服务器内部错误!");
    }
}
